package com.ourhours.message.controller;


import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.ourhours.link.annotation.Permission;
import com.ourhours.link.dto.UserInfoDto;
import com.ourhours.message.common.BaseResult;
import com.ourhours.message.domain.SmsSend;
import com.ourhours.message.domain.Supplier;
import com.ourhours.message.service.SmsSendService;
import com.ourhours.message.service.wrapper.SmsWrapper;
import com.ourhours.message.service.wrapper.SupplierWrapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * <p>
 * 短信记录表 前端控制器
 * </p>
 *
 * @author dalong.wang
 * @since 2018-03-21
 */
@Controller
@RequestMapping("/smsSend")
@Slf4j
public class SmsSendController extends BaseController {

    @Autowired
    SmsSendService smsSendService;

    @Permission("messageSmsSend")
    @GetMapping("/list")
    public String list() {
        return "smsSend/list";
    }

    @Permission("messageSmsSendList")
    @PostMapping("/listPage")
    @ResponseBody
    public BaseResult listPage(SmsSend entity, Integer offset, Integer limit) {
        try {
            UserInfoDto user = getLoginUser();
            entity.setDeleted(0L);
            if (user.getVendorId() != null && user.getVendorId() != 0L) {
                entity.setVendorId(user.getVendorId());
            }
            EntityWrapper<SmsSend> wrapper = new EntityWrapper<SmsSend>(entity);
            wrapper.orderBy("id",false);
            Page<SmsSend> page0 = new Page<>(offset / limit + 1, limit);
            Page<SmsSend> page = smsSendService.selectPage(page0, wrapper);
            log.info("==> SmsSendController.listPage查询短信记录列表成功,结果:{}", page);
            return BaseResult.success(page);
        } catch (Exception e) {
            log.error("==> SmsSendController.listPage查询短信记录列表失败，异常{}", e);
            return BaseResult.failure("查询失败!");
        }
    }
    /*@GetMapping("/sendSms")
    @ResponseBody
    public String sendSms(){
        try {
            smsWrapper.send("13220187546",10001L,"测试");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }*/
}

